SHELL=sh
RM=rm -f
CD=cd
#Define the cross complier
CROSS_COMPILER=arm-uclinuxeabi-
CC=$(CROSS_COMPILER)gcc
CPP=$(CROSS_COMPILER)g++
LD=$(CROSS_COMPILER)ld
OBJCOPY=$(CROSS_COMPILER)objcopy
OBJDUMP=$(CROSS_COMPILER)objdump
OBJNM=$(CROSS_COMPILER)nm
OBJSIZE=$(CROSS_COMPILER)OBJSIZE

#Define C flags
CFLAGS=-c -mcpu=arm920t
CFLAGS+=-Iinc -Os
CFLAGS+=-fno-builtin
CFLAGS+=-Wall -Wstrict-prototypes
CFLAGS+=-Wmissing-declarations -Wmissing-prototypes
CFLAGS+=-Wnested-externs
#Define assembly flags
ASFLAGS=-c -mcpu=arm920t -Iinc
#Define C++ flags
CPPFLAGS=
#Define LD flags
LDFLAGS=-nostdlib -T ram.ld


#Define the object files
OBJS=start.o main.o uart.o

TARGET=sdram
BD=./bd


$(TARGET).bin:$(OBJS)
	@echo
	@echo linking...
	$(LD) $(LDFLAGS) $(OBJS) -o $(BD)/$(TARGET).elf

	@echo
	@echo Creating binary file for download...
	$(OBJCOPY) -O binary $(BD)/$(TARGET).elf $(BD)/$(TARGET).bin

	@echo
	@echo dumping the elf file...
	$(OBJDUMP) -S $(BD)/$(TARGET).elf > $(BD)/$(TARGET).lst

	@echo
	@echo Creating the symbol table...
	$(OBJNM) -a $(BD)/$(TARGET).elf > $(BD)/$(TARGET).sym

	@echo
	@echo Moving all the object files to bd floder...
	mv *.o $(BD)

vpath %.S src
vpath %.c src

%.o:%.c
	@echo
	@echo Compiling $<...
	$(CC) $(CFLAGS)  $< -o $@
%.o:%.S
	@echo
	@echo Assembling $<...
	$(CC) $(ASFLAGS) $< -o $@

clean:
	@echo
	@echo cleaning files
	$(RM) *.o *.elf *.lst *.bin *.sym
	$(CD) $(BD);$(RM) *.o *.elf *.lst *.bin *.sym

.PHONY: clean all







